﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.Composition;

namespace Steve.UI.Controllers
{
    public class CategoryControllerBase : Controller
    {
        [Import]
        public CategoryRepository Repository { get; set; }

        public virtual ActionResult GetCategories(string term)
        {
            if (string.IsNullOrWhiteSpace(term)) return new EmptyResult();

            var categories = Repository.GetCategoriesByDescription(term);

            var model = from c in categories
                        select new Dictionary<string, string>(2) { { "value", c.CategoryName }, { "label", c.CategoryDescription } };

            return Json(model, JsonRequestBehavior.AllowGet);
        }
    }
}